﻿using System.Windows.Controls;

namespace Lib.WPF.Views;
/// <summary>
/// 通用空白页
/// </summary>
public partial class PageEmpty : Page {
    /// <summary>
    /// 构造函数
    /// </summary>
    public PageEmpty() {
        InitializeComponent();
    }
    /// <summary>
    /// 创建实例
    /// </summary>
    public static PageEmpty Create(object Parameter = null) {
        return new PageEmpty(Parameter);
    }
    /// <summary>
    /// 构造函数
    /// </summary>
    public PageEmpty(object Parameter = null) {
        if (Parameter != null) {
            if (Parameter is Control Control) {
                var Panel = Find<Grid>("Panel");
                if (Panel != null) {
                    Panel.Children.Clear();
                    Panel.Children.Add(Control);
                }
            } else {
                var Description = Find<TextBlock>("Description");
                if (Description != null) {
                    Description.Text = Parameter.ToString();
                }

            }
        }
    }
    /// <summary>
    /// 查找具有提供的标识符名的元素
    /// </summary>
    public T Find<T>(string Name) {
        if (string.IsNullOrEmpty(Name)) {
            return default;
        }
        var Element = FindName(Name);
        if (Element == null) {
            return default;
        }
        return (T)Element;
    }
}
